<html>
<head><meta charset="utf-8"><title>Catching and resuming foreign exceptions · project-ffi-unwind · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/index.html">project-ffi-unwind</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html">Catching and resuming foreign exceptions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="189235393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189235393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189235393">(Feb 27 2020 at 17:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/updating.20uninitialized.20swapping/near/189197391" title="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/updating.20uninitialized.20swapping/near/189197391">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/updating.20uninitialized.20swapping/near/189194767" title="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/updating.20uninitialized.20swapping/near/189194767">said</a>:</p>
<blockquote>
<p>Indeed, but there will be in the future.</p>
</blockquote>
<p>this seems pretty relevant for the unwinding discussion then -- adding kinds of uwninding that <code>catch_unwind</code> does not catch could make take_mut, rayon and other libraries unsound</p>
</blockquote>
<p><span class="user-mention silent" data-user-id="143274">Amanieu</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/updating.20uninitialized.20swapping/near/189206676" title="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/updating.20uninitialized.20swapping/near/189206676">said</a>:</p>
<blockquote>
<p>But yes, <code>catch_unwind</code> can only catch Rust panics because it has to return a <code>Box&lt;Any&gt;</code>. This is not possible for foreign exceptions.</p>
<p>I guess we could return a <code>Box&lt;ForeignException&gt;</code>, but then if you try to rethrow that with <code>resume_unwind</code> you get a Rust panic, not the original foreign exception.</p>
</blockquote>
<p>It sounds like we have existing libraries using <code>catch_unwind</code> to do clean-up work that's required for soundness.</p>



<a name="189235651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189235651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189235651">(Feb 27 2020 at 17:34)</a>:</h4>
<p>I would guess (but need to verify somehow) that such clean-up doesn't actually need to interact with the exception objects themselves. In that case, maybe the exception object exposed can (for  now) just be some kind of opaque object that doesn't provide any information  beyond "this is a foreign exception", and in those cases <code>resume_unwind</code> could somehow just resume unwinding with the original exception. Would that be possible?</p>



<a name="189235811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189235811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189235811">(Feb 27 2020 at 17:36)</a>:</h4>
<p>It seems like the fact that <code>resume_unwind</code> creates a <code>panic</code> is an implementation detail, not a requirement of the API... is that correct?</p>



<a name="189237248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189237248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189237248">(Feb 27 2020 at 17:50)</a>:</h4>
<p>It is not possible to "capture" a foreign exception.</p>



<a name="189237322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189237322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189237322">(Feb 27 2020 at 17:51)</a>:</h4>
<p>Let me double-check this</p>



<a name="189237915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189237915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189237915">(Feb 27 2020 at 17:57)</a>:</h4>
<p>I think it might be possible to capture an exception with libunwind.</p>



<a name="189237917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189237917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189237917">(Feb 27 2020 at 17:57)</a>:</h4>
<p>Let me check SEH</p>



<a name="189238042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238042">(Feb 27 2020 at 17:59)</a>:</h4>
<p>It's probably possible, but it would be very difficult (SEH is poorly documented)</p>



<a name="189238313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238313">(Feb 27 2020 at 18:01)</a>:</h4>
<p>Well, if the type is opaque, it just needs to behave like C++'s <code>catch (...) { /* clean-up code */ throw; }</code>, right?</p>



<a name="189238383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238383">(Feb 27 2020 at 18:02)</a>:</h4>
<p>The complication, of course, being that the clean-up takes place between the call to <code>catch_unwind</code> and the call to <code>resume_unwind</code>, rather than in a block <span aria-label="confused" class="emoji emoji-1f615" role="img" title="confused">:confused:</span></p>



<a name="189238407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238407">(Feb 27 2020 at 18:02)</a>:</h4>
<p>Ah but that doesn't work for us. We need to capture the exception into <code> Box</code> in such a way that it can be sent to another thread and rethrown there.</p>



<a name="189238439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238439">(Feb 27 2020 at 18:02)</a>:</h4>
<p>It's closer to C++'s <code>exception_ptr</code></p>



<a name="189238447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238447">(Feb 27 2020 at 18:02)</a>:</h4>
<p>Why sent to another thread? Can't we just require that (at least for now) <code>resume_unwind</code> be called in the same function in which <code>catch_unwind</code> is called?</p>



<a name="189238485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238485">(Feb 27 2020 at 18:03)</a>:</h4>
<p>What do you think rayon is doing with its caught panics? :P</p>



<a name="189238487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238487">(Feb 27 2020 at 18:03)</a>:</h4>
<p>And if it's an opaque object denoting "the current foreign exception", does it even need a handle to the actual exception object?</p>



<a name="189238497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238497">(Feb 27 2020 at 18:03)</a>:</h4>
<p>Uh.... I thought it was just "clean up"</p>



<a name="189238503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238503">(Feb 27 2020 at 18:03)</a>:</h4>
<p>I did not look!</p>



<a name="189238538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238538">(Feb 27 2020 at 18:03)</a>:</h4>
<p>It propagate the panic up to the caller of a <code>join</code>.</p>



<a name="189238549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238549">(Feb 27 2020 at 18:03)</a>:</h4>
<p>That does complicate things. I guess I need to look into what specific guarantees are required for Rayon to be sound when foreign exceptions occur</p>



<a name="189238633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238633">(Feb 27 2020 at 18:04)</a>:</h4>
<p>Well rayon would just crash since there's nothing to catch the foreign exception at the root of the thread.</p>



<a name="189238845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189238845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189238845">(Feb 27 2020 at 18:06)</a>:</h4>
<p>We can definitely return an opaque <code>Box&lt;ForeignException&gt;</code>, that should be relatively easy to do. It might cost us a bit of code size on msvc target since we would be effectively lowering to</p>
<div class="codehilite"><pre><span></span><span class="k">try</span> <span class="p">{</span>
    <span class="n">fn</span><span class="p">();</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="n">rust_panic</span><span class="o">&amp;</span><span class="p">)</span> <span class="p">{</span>
    <span class="c1">// Capture Rust panic</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">(...)</span> <span class="p">{</span>
    <span class="c1">// Capture foreign exception</span>
<span class="p">}</span>
</pre></div>



<a name="189239286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189239286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189239286">(Feb 27 2020 at 18:10)</a>:</h4>
<p>I suspect we'll need to look into modifying the catch/resume API at some point. It seems like we probably want users to be able to catch _just_ Rust panics, if there's no soundness-cleanup required.</p>



<a name="189239663"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189239663" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189239663">(Feb 27 2020 at 18:14)</a>:</h4>
<p>If it's soundness that we are worried about then catching foreign exceptions and returning <code>Box&lt;ForeignException&gt;</code> should fix the soundness issue. Rethrowing the <code>ForeignException</code> as a Rust panic instead of a C++ exception shouldn't cause correctness issues.</p>



<a name="189239764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189239764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189239764">(Feb 27 2020 at 18:15)</a>:</h4>
<p>Of course, this catch would need to ignore forced exceptions. Or it could attempt to catch them and abort. Either way is fine since <code>catch_unwind</code> counts as a destructor for the purposes of FFI unwind rules so you're already in UB land.</p>



<a name="189241080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189241080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189241080">(Feb 27 2020 at 18:27)</a>:</h4>
<p>It seems like there ought to be a way to catch a forced exception, do some clean-up, and then resume from the same thread, though, right?</p>



<a name="189241219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189241219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189241219">(Feb 27 2020 at 18:29)</a>:</h4>
<p>.. but why would you ever want to catch a <code>longjmp</code> or a <code>pthread_exit</code></p>



<a name="189241243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189241243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189241243">(Feb 27 2020 at 18:29)</a>:</h4>
<p>That's just a recipe for disaster in both cases</p>



<a name="189241270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189241270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189241270">(Feb 27 2020 at 18:29)</a>:</h4>
<p>We're better off just letting them unwind through.</p>



<a name="189241429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189241429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189241429">(Feb 27 2020 at 18:31)</a>:</h4>
<p>longjmp across rust code is UB because it may not unwind in some cases.</p>



<a name="189243580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189243580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189243580">(Feb 27 2020 at 18:49)</a>:</h4>
<p>I don't know... I realize asking "why does C++ allow it" is a recipe for banging one's head against one's desk, but I do wonder about whether <code>catch (...)</code> has any actual value or if it was entirely a mistake.</p>



<a name="189295630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189295630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189295630">(Feb 28 2020 at 09:41)</a>:</h4>
<p>maybe another option would be to make <code>catch_panic</code> abort on non-panic unwind, and then if/when we have clear usecases where that is a problem, design another API for them?</p>



<a name="189295693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189295693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189295693">(Feb 28 2020 at 09:42)</a>:</h4>
<p>Either way it requires catching the foreign unwind, which may be non-trivial.</p>



<a name="189295737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189295737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189295737">(Feb 28 2020 at 09:43)</a>:</h4>
<p>And tbh, that code really should have been using scope guard rather then <code>catch_unwind</code>, which is much slower.</p>



<a name="189295755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189295755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189295755">(Feb 28 2020 at 09:43)</a>:</h4>
<p>*for take_mut</p>



<a name="189295813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189295813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189295813">(Feb 28 2020 at 09:44)</a>:</h4>
<p>In the case of rayon <code>catch_unwind</code> is the correct thing to do, but foreign exception currently will just go straight to the root of the thread and abort the whole program, so it's not really unsound.</p>



<a name="189296950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189296950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189296950">(Feb 28 2020 at 10:01)</a>:</h4>
<p>A scope guard only works for rust panics, as std::thread::panicking only returns true when a rust panic has started. It doesn't check if it is currently unwinding.</p>



<a name="189297488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189297488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189297488">(Feb 28 2020 at 10:10)</a>:</h4>
<p>Scope guards work for all types of unwinding.</p>



<a name="189298220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189298220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189298220">(Feb 28 2020 at 10:22)</a>:</h4>
<p>Oh wait I see what you mean.</p>



<a name="189298252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189298252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189298252">(Feb 28 2020 at 10:22)</a>:</h4>
<p>Yea scopeguard only works in the default mode.</p>



<a name="189324719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189324719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189324719">(Feb 28 2020 at 16:21)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Soundness.20concerns.20around.20catch_unwind/near/189294544" title="#narrow/stream/210922-project-ffi-unwind/topic/Soundness.20concerns.20around.20catch_unwind/near/189294544">said</a>:</p>
<blockquote>
<p>it is legitimate (or at least, not unreasonable) for code to assume that every (Rust) function either returns or panics</p>
</blockquote>
<p>This is already wrong – it can also abort/exit though I guess those cases are not too interesting. On Windows abort is implemented as a special kind of unwind though.</p>



<a name="189324921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189324921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189324921">(Feb 28 2020 at 16:23)</a>:</h4>
<p>I’m not sure why you’re saying scope guards work for all types of unwinding. I don’t think they do for arbitrary choices of unwinding implementation and personality function.</p>



<a name="189325047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189325047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189325047">(Feb 28 2020 at 16:24)</a>:</h4>
<p>A perfect example here is, again, windows abort unwind. It uses the same unwinding mechanism it just carries special payload and thus just happens to ignore the typical handlers that may exist on stack of a typical program.</p>



<a name="189330769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189330769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189330769">(Feb 28 2020 at 17:25)</a>:</h4>
<p>On windows we only run destructors for C++ exceptions (-gnu and -msvc) and longjmp (-msvc only). Not for arbitrary SEH exceptions.</p>



<a name="189330919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189330919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189330919">(Feb 28 2020 at 17:27)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> <a href="https://docs.rs/scopeguard/1.1.0/scopeguard/fn.guard_on_unwind.html" target="_blank" title="https://docs.rs/scopeguard/1.1.0/scopeguard/fn.guard_on_unwind.html">https://docs.rs/scopeguard/1.1.0/scopeguard/fn.guard_on_unwind.html</a></p>



<a name="189331061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189331061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189331061">(Feb 28 2020 at 17:28)</a>:</h4>
<p>The is the relevant function. The intent is to only run some cleanup code when unwinding. However this won't work correctly if a foreign exception comes, since it checks <code>std::thread::panicking</code> which will return false for foreign exceptions.</p>



<a name="189334373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189334373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189334373">(Feb 28 2020 at 18:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/189324719" title="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/189324719">said</a>:</p>
<blockquote>
<p>This is already wrong – it can also abort/exit though I guess those cases are not too interesting. On Windows abort is implemented as a special kind of unwind though.</p>
</blockquote>
<p>in that case nothing matters as no code (of this program) runs any more. but, sure, if you want to be explicit about it:<br>
every Rust function either returns or panics or halts execution of the abstract machine / the entire program.</p>



<a name="189334499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189334499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189334499">(Feb 28 2020 at 18:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/189325047" title="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/189325047">said</a>:</p>
<blockquote>
<p>A perfect example here is, again, windows abort unwind. It uses the same unwinding mechanism it just carries special payload and thus just happens to ignore the typical handlers that may exist on stack of a typical program.</p>
</blockquote>
<p>I think different people are using "unwinding" in different ways here... what you describe here sounds to me like an unobservable implementation detail of how abort is implemented on windows</p>



<a name="189334728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189334728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189334728">(Feb 28 2020 at 18:05)</a>:</h4>
<p>and sure, one can do all sorts of nastiness by messing with SEHs on Windows, or messing with <code>/proc/self/mem</code> on Linux. all of that is "platform-UB", as in the specific implementation of the abstract machine for that platform just assumes you will not do that.<br>
the parts we care about are cases of unwinding that we do support and specify. so far that's just panicking so "scope guards work for all [supported] types of unwinding" is trivially true. once more types of unwinding are possible, well, things become interesting and "scope guards work for all [supported] types of unwinding" is likely something we want to guarantee.</p>



<a name="189368294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189368294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189368294">(Feb 29 2020 at 01:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/189334499" title="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/189334499">said</a>:</p>
<blockquote>
<p>I think different people are using "unwinding" in different ways here... what you describe here sounds to me like an unobservable implementation detail of how abort is implemented on windows</p>
</blockquote>
<p>It is not unobservable, you can deal with it if you _really_ want to. As thus we need to be extremely careful about what terminology we use. And exactly the point I was trying to make: saying that "all" unwinds can be handled… or anything to that effect… is not tenable unless we try _really_ hard to actually enumerate all possible ways of unwinding, including the cases where they are mostly stable implementation details.</p>



<a name="189368565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189368565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189368565">(Feb 29 2020 at 01:29)</a>:</h4>
<p>Saying that C++ exceptions, longjmp and Rust panics are supported and everything else is still UB is way more correct than "all unwinding"</p>



<a name="189368593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189368593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189368593">(Feb 29 2020 at 01:30)</a>:</h4>
<p>I rest my case.</p>



<a name="189369485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189369485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189369485">(Feb 29 2020 at 01:47)</a>:</h4>
<p>I understand you're making a point, but "I rest my case" is somewhat combative.</p>



<a name="189369769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189369769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189369769">(Feb 29 2020 at 01:54)</a>:</h4>
<p>First dictionary in the search engine says:</p>
<blockquote>
<p>I have completed the presentation of my argument.</p>
</blockquote>
<p>I don’t see how that’s combative, and it wasn't meant to come across as such.</p>



<a name="189382550"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/189382550" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#189382550">(Feb 29 2020 at 08:47)</a>:</h4>
<p>I think it is unobservable without UB -- how would I observe it?</p>
<p>I think you basically confirmed what I said -- we have to carefully distinguish "unwinnding in Rust, part of the spec, observable in the Abstract Machine" from "unwindining on the underlying implementation".</p>



<a name="191291999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191291999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191291999">(Mar 20 2020 at 19:35)</a>:</h4>
<p>Update: actually it turns out that we can't safely capture a foreign exception and then resume it on a different thread.</p>



<a name="191292182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191292182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191292182">(Mar 20 2020 at 19:36)</a>:</h4>
<p>C++ exceptions have pointers into thread-local state, which means they can't be <code>Send</code>. Therefore we can't capture it in a <code>Box&lt;Any + Send&gt;</code>.</p>



<a name="191292253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191292253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191292253">(Mar 20 2020 at 19:37)</a>:</h4>
<p>That makes sense to me - does the standard library provide a copy operator?</p>



<a name="191292378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191292378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191292378">(Mar 20 2020 at 19:38)</a>:</h4>
<p>The thing is, we're only dealing with exception objects at the libunwind level. We don't see the C++-specific state.</p>



<a name="191292854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191292854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191292854">(Mar 20 2020 at 19:43)</a>:</h4>
<p>The "proper" way of sending a C++ exception to another thread is to catch it with <code>__cxa_begin_catch</code>, which removes it from the thread's linked list of active exceptions. The exception itself is reference-counted and can be rethrown in another thread.</p>



<a name="191292867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191292867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191292867">(Mar 20 2020 at 19:43)</a>:</h4>
<p>But we can't do that since we would need to depend on the C++ runtime for unwinding.</p>



<a name="191293097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191293097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191293097">(Mar 20 2020 at 19:45)</a>:</h4>
<p>Wouldn't we only need to do that in cases where the C++ runtime is already linked in the process, though?</p>



<a name="191293903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191293903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191293903">(Mar 20 2020 at 19:51)</a>:</h4>
<p>Hmm. I guess we could do some trickery with weak symbols.</p>



<a name="191294502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191294502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191294502">(Mar 20 2020 at 19:56)</a>:</h4>
<p>Won't work on OSX though, I'm pretty sure.</p>



<a name="191295937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191295937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191295937">(Mar 20 2020 at 20:08)</a>:</h4>
<p>Then again, on macOS libc++ is always available as part of the system, so it doesn't matter too much if we link to it.</p>



<a name="191296100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191296100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191296100">(Mar 20 2020 at 20:10)</a>:</h4>
<p>Definitely won't fly on mingw though</p>



<a name="191298495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191298495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191298495">(Mar 20 2020 at 20:31)</a>:</h4>
<p>If an exception is thrown on another thread, the expectation that it would have an upstream handler somewhere?</p>



<a name="191301833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191301833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191301833">(Mar 20 2020 at 21:01)</a>:</h4>
<p>Consider something like this: a C++ program uses a Rust lib that uses rayon.</p>



<a name="191302037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191302037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191302037">(Mar 20 2020 at 21:02)</a>:</h4>
<ul>
<li>C++ calls Rust</li>
<li>Rust invokes code via rayon on another thread</li>
<li>Rust code in that other thread invokes a C++ callback</li>
<li>C++ throws an exception</li>
<li>Exception unwinds to rayon in the thread, which catches it and rethrows it in the caller's thread.</li>
<li>Exception unwinds out of Rust back into the original C++ caller.</li>
</ul>



<a name="191302737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191302737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191302737">(Mar 20 2020 at 21:08)</a>:</h4>
<p>Ah, okay, so it definitely needs to be the original exception</p>



<a name="191530398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191530398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191530398">(Mar 23 2020 at 20:17)</a>:</h4>
<p>It seems like more and more we are saying that that C++ exceptions propagating into Rust is something done "with caution" at best</p>



<a name="191530483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191530483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191530483">(Mar 23 2020 at 20:18)</a>:</h4>
<p>In some sense, the only case that we're <em>really</em> enabling is the case of a Rust panic propagating across foreign frames</p>



<a name="191950815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191950815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191950815">(Mar 26 2020 at 21:21)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I have some questions -- you mentioned that rethrowing a <code>Box&lt;ForeignException&gt;</code> will be translated to a Rust panic. Is that because of the ability to send the <code>Box&lt;dyn Any&gt;</code> across threads?</p>



<a name="191950824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191950824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191950824">(Mar 26 2020 at 21:21)</a>:</h4>
<p>Or are there other reasons?</p>



<a name="191950866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191950866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191950866">(Mar 26 2020 at 21:21)</a>:</h4>
<p>I'm wondering basically whether a <code>catch_unwind2</code> API <em>could</em> permit catching and rethrowing foreign exceptions</p>



<a name="191950880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191950880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191950880">(Mar 26 2020 at 21:22)</a>:</h4>
<p>Ah, right, it had also to do with the C++ runtime</p>



<a name="191950934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191950934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191950934">(Mar 26 2020 at 21:22)</a>:</h4>
<p>(Is there any way to make that a bit more opt-in?)</p>



<a name="191951007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951007">(Mar 26 2020 at 21:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> See this comment: <a href="https://github.com/rust-lang/rust/pull/70212#issuecomment-602230588" title="https://github.com/rust-lang/rust/pull/70212#issuecomment-602230588">https://github.com/rust-lang/rust/pull/70212#issuecomment-602230588</a></p>



<a name="191951165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951165">(Mar 26 2020 at 21:24)</a>:</h4>
<p>I don't think any API change is necessary to support rethrowing foreign exceptions if we decide to support it in the future. We could just make <code>Box&lt;ForeignException&gt;</code> magically turn back into the original exception.</p>



<a name="191951348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951348">(Mar 26 2020 at 21:26)</a>:</h4>
<p>I see</p>



<a name="191951383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951383">(Mar 26 2020 at 21:26)</a>:</h4>
<p>I guess my question is --</p>



<a name="191951390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951390">(Mar 26 2020 at 21:26)</a>:</h4>
<p>could we set  things up in such a way that</p>



<a name="191951400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951400">(Mar 26 2020 at 21:27)</a>:</h4>
<p>if you used the <code>catch_unwind_cpp</code>,</p>



<a name="191951404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951404">(Mar 26 2020 at 21:27)</a>:</h4>
<p>that did these extra calls,</p>



<a name="191951419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951419">(Mar 26 2020 at 21:27)</a>:</h4>
<p>but invoking that also triggers us linking in C++ library :)</p>



<a name="191951450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951450">(Mar 26 2020 at 21:27)</a>:</h4>
<p>e.g., in my ideal "mental model", it'd be in some crate where the c++ lib is a dependency</p>



<a name="191951566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951566">(Mar 26 2020 at 21:28)</a>:</h4>
<p>Perhaps it would be better to have a compiler/linker flag saying "<code>catch_unwind</code> should be able to catch C++ exceptions"?</p>



<a name="191951605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951605">(Mar 26 2020 at 21:29)</a>:</h4>
<p>We could try doing magic with <code>dlsym</code>to check if <code>__cxa_begin_catch</code> exists at runtime.</p>



<a name="191951622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951622">(Mar 26 2020 at 21:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120076">BatmanAoD (Kyle Strand)</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/191951566" title="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/191951566">said</a>:</p>
<blockquote>
<p>Perhaps it would be better to have a compiler/linker flag saying "<code>catch_unwind</code> should be able to catch C++ exceptions"?</p>
</blockquote>
<p>yeah that's another option, I was pondering that</p>



<a name="191951646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951646">(Mar 26 2020 at 21:29)</a>:</h4>
<p>I'm just imagining that if you <em>were</em> trying to intermix C++ and Rust unwinding, you'd probably want your exception to have "true fidelity"</p>



<a name="191951734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951734">(Mar 26 2020 at 21:30)</a>:</h4>
<p>I can have a go at implementing runtime symbol lookup.</p>



<a name="191951796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191951796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191951796">(Mar 26 2020 at 21:31)</a>:</h4>
<p>It honestly feels easier than messing with compiler options</p>



<a name="191952087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191952087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> BatmanAoD (Kyle Strand) <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191952087">(Mar 26 2020 at 21:33)</a>:</h4>
<p>And of course much nicer from a user's perspective, I think!</p>



<a name="191957161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191957161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191957161">(Mar 26 2020 at 22:28)</a>:</h4>
<p>I know that in a past project, I managed to get C++ exceptions working by capturing them into C++'s exception_ptr and then passing that as a pointer across the FFI boundary, panicking, catching that at the next ffi boundary, and so forth</p>



<a name="191957193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191957193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191957193">(Mar 26 2020 at 22:29)</a>:</h4>
<p>Obviously in the ideal world that would just happen on its own, though.</p>



<a name="191957216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/191957216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#191957216">(Mar 26 2020 at 22:29)</a>:</h4>
<p>(Writing those shims wasn't fun.)</p>



<a name="192098037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/210922-project-ffi-unwind/topic/Catching%20and%20resuming%20foreign%20exceptions/near/192098037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions.html#192098037">(Mar 28 2020 at 01:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/191957161" title="#narrow/stream/210922-project-ffi-unwind/topic/Catching.20and.20resuming.20foreign.20exceptions/near/191957161">said</a>:</p>
<blockquote>
<p>I know that in a past project, I managed to get C++ exceptions working by capturing them into C++'s exception_ptr and then passing that as a pointer across the FFI boundary, panicking, catching that at the next ffi boundary, and so forth</p>
</blockquote>
<p>interesting</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>